<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>插入链接</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" src="../internal.js"></script>
    <style type="text/css">
        *{color: #838383}
        body {
            font-size: 12px;
            width:382px;
            height: 100px;
            overflow: hidden;
            margin:0px;padding:0px;
        }
         span.txt{width: 60px;height:30px;line-height: 30px;display: block;float:left}
        .content{
            padding: 9px 0px 0px 15px;
            height:100%;
        }
        #link_href,
        #title{width:286px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0px; margin: 0px; line-height:21px}

        #link_href{width:208px}
        .content table{padding:0px;margin:0px}
        .content table tr{padding:0px;margin:0px; list-style: none;height: 20px; line-height: 20px;}

        .red{color:red;}
    </style>
</head>
<body>
<div class="content">
    <table>
        <tr>
            <td><span class="txt">链接地址：</span>
                <select id="protocol">
                    <option value="http://">http://</option>
                    <option value="https://">https://</option>
                </select>
                <input id="link_href" type="text" /><br/>
            <span id="msg2" class="red"></span></td>
        </tr>
        <tr>
            <td><span class="txt">标题：</span><input id="title" type="text"/></td>
        </tr>
        <tr>
             <td><span>是否在新窗口打开：</span><input id="target" type="checkbox"/></td>
        </tr>
    </table>

</div>
<script type="text/javascript">

    var link = editor.selection.getRange().collapsed ? editor.queryCommandValue( "link" ) : editor.selection.getStart(),url;
    link = domUtils.findParentByTagName( link, "a", true );
    if(link){
        url = link.getAttribute( 'data_ue_src' ) || link.getAttribute( 'href', 2 );
    }
    $G("title").value = url ? link.title : "";
    $G("protocol").value = !url || /^(?:http:\/\/)/ig.test(url) ? "http://" : "https://";
    $G("link_href").value = url ? url.replace(/^(?:https?:\/\/)|(?:\/)$/ig,"") : '';
    $G("target").checked = url && link.target == "_blank" ? true :  false;

    var ipt = $G("link_href");
    $focus(ipt);
    ipt.style.cssText = 'border:1px solid #ccc;background-color:#fafafa;';
    ipt.onfocus = function(){
        this.style.cssText = 'border:1px solid #ccc;background-color:#fff;';
    }
    ipt.onblur = function(){
        this.style.cssText = 'border:1px solid #ccc;background-color:#fafafa;';
    }

   
    function handleDialogOk(){
        var href;
        if(href = $G('link_href').value.replace(/^\s+|\s+$/g, '')){
            editor.execCommand('link', {
                'href' : $G("protocol").value + href,
                'target' : $G("target").checked ? "_blank" : '_self',
                'title' : $G("title").value.replace(/^\s+|\s+$/g, ''),
                'data_ue_src':$G("protocol").value + href
            });
            dialog.close();
        }else{
            $G("msg2").innerHTML = "请输入链接地址！";
        }
    }
    dialog.onok = handleDialogOk;
    $G('link_href').onkeydown = function(evt){
        evt = evt || window.event;
        if (evt.keyCode == 13) {
            handleDialogOk();
            return false;
        }
    };


</script>
</body>
</html>
